const express = require('express')
const app = express()

app.use((req, res, next) => {
  const arr = ['http://127.0.0.1:5500', 'http://127.0.0.1:5501', 'http://127.0.0.1:5501']
  if (arr.includes(req.headers.origin)) {
    // 设置允许跨域
    res.set('Access-Control-Allow-Origin', req.headers.origin)
    res.set('Access-Control-Allow-Headers', 'token')
  }
  next()
})

app.get('/userInfo', (req, res) => {
  res.send({
    code: 10000,
    msg: '查询失败',
    data: {
      name: '程龙',
      age: 222,
      sex: '男'
    }
  })
})

app.listen(8080, () => {
  console.log('成功');
})